package com.cn.ant.modules.score.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.common.utils.Identities;
import com.cn.ant.modules.score.dao.YfdInfoDao;
import com.cn.ant.modules.score.entity.YfdInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 一分段信息Service
 * @author AntDream
 * @version 2015-08-17
 */
@Service
@Transactional(readOnly = true)
public class YfdInfoService extends BaseService {

    @Autowired
	private YfdInfoDao yfdInfoDao;

	public YfdInfo get(String id) {
		return yfdInfoDao.get(id);
	}
	
	public List<YfdInfo> findList(YfdInfo yfdInfo) {
		return yfdInfoDao.findList(yfdInfo);
	}
	
	public Page<YfdInfo> findPage(Page<YfdInfo> page, YfdInfo yfdInfo) {
	    yfdInfo.setPage(page);
        page.setList(yfdInfoDao.findList(yfdInfo));
        return page;
	}
	
	@Transactional(readOnly = false)
	public void save(YfdInfo yfdInfo) {
	    if (yfdInfo.getIsNewRecord()) {
            yfdInfo.preInsert();
            yfdInfoDao.insert(yfdInfo);
        } else {
            yfdInfo.preUpdate();
            yfdInfoDao.update(yfdInfo);
        }
	}

	@Transactional(readOnly = false)
	public void batchInsert(List<YfdInfo> list) {
		if (list != null && !list.isEmpty()) {
			for (int i = 0; i < list.size(); i++) {
				list.get(i).setId(Identities.generateUUID());
				list.get(i).preInsert();
			}
			yfdInfoDao.batchInsert(list);
		}
	}

	@Transactional(readOnly = false)
	public void delete(YfdInfo yfdInfo) {
		yfdInfoDao.delete(yfdInfo);
	}
	
}